<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\request;

/**
 *
 * 支付页面
 */
class Ofrecharge extends Base{
    //线上支付页面
    //线下支付页面
    public function ofrecharge(){
        //线下转账账号
        $list=Db::name('account_receivable')->where('statue','1')->select();
        $min=Db::name('config')->where('id=3')->field('value')->find();
        $min=$min['value'];
        $this->assign('min',$min);
        $this->assign('list',$list);
        return $this->fetch('Recharge/offline_recharge');
    }

    //接收付款页面值
    public function  ofadd(){
         $data=$this->request->post();
         $data=myarr($data);
         $file = request()->file('image');
        if($file==''){
            return "<script>alert('请上传图片凭证');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
        }
        if($data['type']==''){
            return "<script>alert('请选择银行账户');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
        }
        //充值最低金额
        $min=Db::name('config')->where('id=3')->field('value')->find();
        $min=$min['value'];
        //是否有非法字符
        if(preg_match("/[\',:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",$data['amount'])){
            return "<script>alert('请输入正确的金额');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
        }
        //最低充值金额
        if($data['amount']<$min){
            return "<script>alert('充值金额必须大于{$min}元');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
        }
        //转账账号
       $remarks=Db::name('account_receivable')->where('id',$data['type'])->find();
         //$data['platformtradeNo']=$this->upload($file);
         $ste=array();
         $ste['uid']=Session::get('uid');
         $ste['amount']=$data['amount'];
         $ste['tradeNo']=orderNum();
         $ste['platformtradeNo']=$this->upload($file);
         $ste['paymentCode']=0;
        $ste['payee']=$remarks['accountnumber'];
         $ste['remarks']=$remarks['accountnumber'].$remarks['payee'];
        $ste['poundage']=0;
        $ste['offline']=0;
        $arr=Db::table('lc_user_recharge')->insert($ste);
        //var_dump($arr);die;
        if($arr){
                  return "<script>alert('线下充值资料提交成功');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
                }else{
                   return "<script>alert('线下充值资料提交失败');window.location.href='".url('/home/Ofrecharge/ofrecharge')."'</script>";
                      }
        //var_dump($ste);die;
    }

    //上传图片
    public function upload($file){
        // 移动到框架应用根目录/public/uploads/ 目录下
        if($file){
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
               // echo $info->getExtension();
                // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                return $info->getSaveName();
                // 输出 42a79759f284b767dfcb2a0197904287.jpg
                //echo $info->getFilename();
            }else{
                // 上传失败获取错误信息
                 $file->getError();
            }
        }
    }



}